package com.bt.lms.ui.page.teaching.supervise.action;

import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.utils.MyVBox;
import com.bt.lms.ui.page.teaching.supervise.PageTeacherList;
import com.bt.lms.ui.vo.PageSkipInfo;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField; 

/**
 * 检索教师列表按钮事件（新增教师值机界面）
 */
public class InquireBtnAction implements EventHandler {

    /**
     * 盒子
     */
    private final MyVBox myVBox;

    /**
     * 索引
     */
    private final int i;

    /**
     * 界面跳转信息
     */
    private final PageSkipInfo pageSkipInfo;

    /**
     * 构建事件
     *
     * @param myVBox       所在盒子
     * @param i            所在位置
     * @param pageSkipInfo 界面跳转信息
     */
    public InquireBtnAction(MyVBox myVBox, int i, PageSkipInfo pageSkipInfo) {
        this.myVBox = myVBox;
        this.i = i;
        this.pageSkipInfo = pageSkipInfo;
    }

    /**
     * 事件实现
     *
     * @param event the event which occurred
     */
    @Override
    public void handle(Event event) {

        //获取查询条件
        TextField teacherTF = (TextField) myVBox.lookup("#teacherTF");
        String text = teacherTF.getText();

        ObservableList<Node> children = myVBox.getChildren();
        int size = children.size();
        //教师列表界面
        PageTeacherList pageTeacherList = new PageTeacherList(text);


        if (size>2){
            children.set(i, pageTeacherList);
            //添加按钮（确认和取消）
            MyHBox controlHBox = new MyHBox();
            controlHBoxInit(controlHBox);
        }else {
            children.add(i, pageTeacherList);
        }



    }

    /**
     * 控制区域初始化
     *
     * @param controlHBox 控制区域
     */
    private void controlHBoxInit(   MyHBox controlHBox) {

        //布局
        Insets insets = new Insets(10);
        controlHBox.setPadding(insets);
        controlHBox.setSpacing(10);
        controlHBox.setAlignment(Pos.CENTER);

        //组件(确认)
        Button saveBtn = new Button("确认");
        //大小控制
        Insets saveBtnInsets = new Insets(10, 20, 10, 20);
        saveBtn.setPadding(saveBtnInsets);
        //组件添加
        ObservableList<Node> saveBtnChildren = controlHBox.getChildren();
        saveBtnChildren.add(saveBtn);

        //组件(取消)
        Button cancelBtn = new Button("取消");
        //大小控制
        Insets cancelBtnInsets = new Insets(10, 20, 10, 20);
        cancelBtn.setPadding(cancelBtnInsets);
        //事件
        PageAddCheckInCancelBtnAction pageAddCheckInCancelBtnAction = new PageAddCheckInCancelBtnAction(pageSkipInfo);
        cancelBtn.setOnAction(pageAddCheckInCancelBtnAction);
        //组件添加
        ObservableList<Node> cancelBtnChildren = controlHBox.getChildren();
        cancelBtnChildren.add(cancelBtn);

    }

}
